<%@page import="fi.foyt.cs.Settings"%>
<%@page import="fi.foyt.cs.api.SystemProperty"%>
<%@page import="fi.foyt.cs.persistence.domainmodel.system.Property"%>
<%@page import="fi.foyt.cs.controller.SystemController"%>
<%@page import="fi.foyt.cs.persistence.domainmodel.task.GeneralTask"%>
<%@page import="fi.foyt.cs.controller.TaskController"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ page import="fi.foyt.cs.persistence.domainmodel.task.TaskType"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="../fragments/head.jsp"></jsp:include>
</head>
<body>
	<jsp:include page="../fragments/header.jsp"></jsp:include>

	<%
	  SystemController systemController = new SystemController();
	  
	  if ("POST".equals(request.getMethod())) {
	    for (SystemProperty systemProperty : SystemProperty.values()) {
	      String value = request.getParameter("property." + systemProperty.name());
	      systemController.setPropertyValue(systemProperty.getInternalName(), value);
	    }
	    
	    Settings.flushSettings();
	  }
	%>

	<h1>System Properties</h1>

	<form method="POST">
		<table>
			<tr>
				<th>Name</th>
				<th>Value</th>
			</tr>

      <c:set var="index" value="0"/>
      <%
        for (SystemProperty systemProperty : SystemProperty.values()) {
          pageContext.setAttribute("property", systemProperty.name());
          pageContext.setAttribute("value", Settings.getValue(systemProperty));
      %>
	      <tr>
	        <td> ${property} </td>
	        <td> <input type="text" value="${value}" name="property.${property}" size="100"/> </td>
	      </tr>
	      <c:set var="index" value="${index + 1}"/>
      <%
        }
      %>
		</table>

		<input type="submit" value="Save" />
	</form>

	<jsp:include page="../fragments/footer.jsp"></jsp:include>
</body>
</html>